<?php

namespace App\Http\Validate\Purchase;

use App\Http\Validate\BaseValidate;

/**
 * 权限组验证器
 */
class PurchaseOrder extends BaseValidate
{
    //验证规则
    protected $rule = [];
    //自定义验证信息
    protected $message = [];

    public function __construct($doaction = 'mainadd')
    {
        if ($doaction == 'mainadd') {
            $this->rule = [
                'pa_id' => 'required',
                'order_date' => 'required',
                'suborder' => 'required'
            ];
            $this->message = [
                'pa_id.required' => '合同号未选择',
                'order_date.required' => '单据日期未选择',
                'suborder.required' => '订单件数不能为空',
            ];
        } elseif($doaction == 'addbyform'){
            $this->rule = [
                'pa_type' => 'required',
                'custom_id' => 'required',
                'pa_settle_company_id' => 'required',
                'settle_model' => 'required|in:1,2,3',
                'invoice_type' => 'required|in:1,2',
                'order_date' => 'required',
                'suborder' => 'required'
            ];
            $this->message = [
                'pa_type.required' => '订单类型不能为空',
                'custom_id.required' => '供应商未选择',
                'pa_settle_company_id.required' => '结算公司未选择',
                'pa_type.required' => '订单类型不能为空',
                'settle_model.required' => '结算模式未选择',
                'settle_model.in' => '结算模式非法参数',
                'invoice_type.required' => '票据类型未选择',
                'invoice_type.in' => '票据类型非法参数',
                'order_date.required' => '单据日期未选择',
                'suborder.required' => '订单件数不能为空',
            ];

        }elseif ($doaction == 'subadd') {
            $this->rule = [
                'stock_id'=>'required',
                // 'count' => 'required|integer|gt:0',
            ];
            $this->message = [
                'stock_id.required' => '库存信息未选择',
                'count.required' => '订单件数不能为空',
                'count.integer' => '订单件数不可小于0',
                'count.gt' => '订单件数不可小于0',
            ];
        }elseif ($doaction == 'subaddbyform') {
            $this->rule = [
                'stock_id'=>'required',
                'base_price' => 'required|integer|gt:0',
                'add_price' => 'required|integer|gte:0',
                // 'count' => 'required|integer|gt:0',
            ];
            $this->message = [
                'stock_id.required' => '库存信息未选择',
                'count.required' => '订单件数不能为空',
                'base_price.required' => '基价不能为空',
                'base_price.integer' => '基价需大于0',
                'base_price.gt' => '基价需大于0',
                'add_price.required' => '加价不能为空',
                'add_price.integer' => '加价不可小于0',
                'add_price.gte' => '加价不可小于0',
                'count.integer' => '订单件数不可小于0',
                'count.gt' => '订单件数不可小于0',
            ];
        } elseif ($doaction == 'subedit') {
            $this->rule = [
                'id'=>'required',
                'stock_id'=>'required',
                'count' => 'required|integer|gt:0',
            ];
            $this->message = [
                'id.required' => '参数错误',
                'stock_id.required' => '库存信息未选择',
                'count.required' => '订单件数不能为空',
                'count.integer' => '订单件数不可小于0',
                'count.gt' => '订单件数不可小于0',
            ];
        } elseif ($doaction == 'subeditbyform') {
            $this->rule = [
                'id'=>'required',
                'stock_id'=>'required',
                'count' => 'required|integer|gt:0',
                'base_price' => 'required|integer|gt:0',
                'add_price' => 'required|integer|gte:0',
            ];
            $this->message = [
                'id.required' => '参数错误',
                'stock_id.required' => '库存信息未选择',
                'count.required' => '订单件数不能为空',
                'count.integer' => '订单件数不可小于0',
                'count.gt' => '订单件数不可小于0',
                'base_price.required' => '基价不能为空',
                'base_price.integer' => '基价需大于0',
                'base_price.gt' => '基价需大于0',
                'add_price.required' => '加价不能为空',
                'add_price.integer' => '加价不可小于0',
                'add_price.gte' => '加价不可小于0',
            ];
        } elseif ($doaction == 'subeditbysale') {
            $this->rule = [
                'id'=>'required',
                'stock_id'=>'required',
                'price' => 'required|integer|gt:0',
//                'base_price' => 'required|integer|gt:0',
            ];
            $this->message = [
                'id.required' => '参数错误',
                'stock_id.required' => '库存信息未选择',
                'price.required' => '单价不能为空',
                'price.integer' => '单价需大于0',
                'price.gt' => '单价需大于0',
//                'base_price.required' => '基价不能为空',
//                'base_price.integer' => '基价需大于0',
//                'base_price.gt' => '基价需大于0',
            ];
        } elseif ($doaction == 'otherfee') {
            $this->rule = [
                'fee_type_id'=>'required|integer|gt:0',
                'fee_date'=>'required',
                'fee_name'=>'required',
                'company_name'=>'required',
                'price' => 'required|integer|gt:0',
            ];
            $this->message = [
                'fee_type_id.required' => '费用类型未选择',
                'fee_type_id.integer' => '费用类型参数错误',
                'fee_type_id.gt' => '费用类型参数错误',
                'fee_date.required' => '费用日期不能为空',
                'fee_name.required' => '费用名称不能为空',
                'company_name.required' => '单位名称不能为空',
                'price.required' => '价格不能为空',
                'price.integer' => '价格不可小于0',
                'price.gt' => '价格不可小于0',
            ];
        }  elseif ($doaction == 'getbankinfowithorderarr') {
            $this->rule = [
                'order_id_arr' => 'required|array',
                'order_id_arr.*' => 'integer',
                'pa_type' => 'required|integer|between:1,4',
            ];
            $this->message = [
                'order_id_arr.required' => '费用类型未选择',
                'pa_type.required' => '价格类型不能为空',
            ];
        }  else {
            $this->rule = [
                'type' => 'required',
                'custom_id' => 'required',
                'contract_no' => 'required',
                'steel_attr_company_id' => 'required',
                'contract_date' => 'required',
                'weight' => 'required',
                'settle_model' => 'required',
                // 'price' => 'required',
                'invoice_type' => 'required',
                'pay_type' => 'required',
                'settle_company_id' => 'required',
                'contract_filepath' => 'required',
            ];
            $this->message = [
                'type.required' => '参数错误',
                'custom_id.required' => '供应商信息未选择',
                'contract_no.required' => '合同编号未填写',
                'steel_attr_company_id.required' => '钢厂未选择',
                'contract_date.required' => '日期未选择',
                'weight.required' => '协议量未填写',
                'settle_model.required' => '结算模式未选择',
                'price.required' => '单价未填写',
                'invoice_type.required' => '票据类型未选择',
                'pay_type.required' => '付款方式未选择',
                'settle_company_id.required' => '结算公司未选择',
                'contract_filepath.required' => '合同扫描件未上传',
            ];
        }
    }
}
